package paneles
import org.apache.wicket.markup.html.panel.Panel
import modelo.Jugador
import org.apache.wicket.model.IModel
import org.apache.wicket.markup.html.WebPage
import org.apache.wicket.markup.html.basic.Label
import org.apache.wicket.markup.html.form.CheckBox
import org.apache.wicket.markup.html.form.DropDownChoice
import org.apache.wicket.markup.html.form.Form
import org.apache.wicket.markup.html.form.TextField
import org.apache.wicket.markup.html.panel.FeedbackPanel
import org.uqbar.commons.model.UserException
import org.uqbar.wicket.xtend.WicketExtensionFactoryMethods
import org.uqbar.wicket.xtend.XButton
import modelo.Zombie
import org.uqbar.wicket.xtend.XLink
import org.apache.wicket.model.PropertyModel
import exepciones.perdisteException
import modelo.Terreno

class AtackPanel extends Panel {
	extension WicketExtensionFactoryMethods = new WicketExtensionFactoryMethods
	Jugador jugador
	
	new(String id, Jugador jugador) {
		super(id)
		this.jugador = jugador
		
		this.addChild(new Botonera("botonera", jugador, this))
		
		val atakForm = new Form<Jugador>("jardinosa", jugador.asCompoundModel)
		this.agregarCamposEdicion(atakForm)
		this.agregarAcciones(atakForm, id)
		this.addChild(atakForm)
 
	}

	def agregarAcciones(Form<Jugador> form, String id) {
		form.addChild(
			new XButton("BotonAtk") => [
				onClick = [|
					try{
						jugador.primerAtaque()
						this.replaceWith(new PanelJardin(id, jugador))
					} catch(NullPointerException e){
						info("elegi un zombie")
					} catch(IllegalArgumentException e){
						info("elegi un zombie")
					} catch(UserException e){
						info(e.getMessage())
						if (e.getMessage() == "perdiste la partida"){
							this.replaceWith(new LOSEpanel(id, jugador))	
						}
					}
			]
			])	}

	def agregarCamposEdicion(Form<Jugador> form) {
		val choice = new DropDownChoice<Zombie>("zombieSeleccionado") => [
				choices = loadableModel([|jugador.sistemaBase.zombiesDisponibles])
				choiceRenderer = choiceRenderer([Zombie z| z.getNombre()])
			]
		info("")
		form.addChild(choice)
		form.addChild(new FeedbackPanel("feedbackPanel"));	
	}

}
